﻿using Assets.Scripts.Net.Loader;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI.Panel
{

    public enum LoadingType
    {
        WWWLoading,//网络资源的加载
        ExamLoading,//题目资源的加载
    }

    public class LoadingPanel:UIBase<LoadingPanel>
    {

        public Text ProgressText;
        public Image Sliderbar;

        private LoadingType loadingType { get; set; }

        protected override UIType UIType
        {
            get { return UIType.Panel;}
        }

        protected override void InitOnAwake()
        {
            AutoFindComponent(transform, true); 
        }

        public void Init(LoadingType type)
        {
            loadingType = type;
        }

        protected override void Update()
        {
            int progress = 0;
            switch (loadingType)
            {
                case LoadingType.ExamLoading:
                    Sliderbar.fillAmount = ExamPanel._Instance.DownLoadProgress;
                    progress = Mathf.FloorToInt(ExamPanel._Instance.DownLoadProgress*100);
                    ProgressText.text = progress + "%";
                    break;
                case LoadingType.WWWLoading:
                    Sliderbar.fillAmount = WWWLoadManager.Instance().DownLoadProgress;
                    progress = Mathf.FloorToInt(WWWLoadManager.Instance().DownLoadProgress*100);
                    ProgressText.text = progress + "%";
                    break;
            }
            if (progress >= 100)
            {
                Exit();
            }
        }
    }
}